<template>
    <view class="content">
        <view class="item" v-for="(item, index) in 2" :key="index" @click="doReceive(item)">
            <image src="../../static/image/g_coupon.png" class="img"></image>
            <view class="u-flex-1">
                <view class="price">
                    ￥<text>10</text>满100元使用
                </view>
                <view class="time">到期时间 2024-12-31 12:30</view>
                <view class="down">
                    <view class="u-flex-1">规则说明：指定商品可用</view>
                    <view class="btn">选择使用</view>
                </view>
            </view>
        </view>
        
        <view style="height: 94rpx;padding-top: 30rpx;">
            <u-loadmore :status="status" v-if="status != 'loadmore'" />
        </view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                status: 'loadmore', //是否显示没有更多了
                page: 1,
                list: [],
                money: 0,
            };
        },
        onLoad(option) {
            this.money = option.money
            // this.getList()
        },
        onReachBottom() {
        	if(this.page == 1){return}
        	// this.getList()
        },
        methods: {
            // 选择使用
            doReceive(item) {
                uni.$emit('ChooseCoupon', item)
                this.$backT()
            },
            
            // 获取列表
            getList() {
            	if (this.status == 'nomore') return;
            	this.status = 'loading';
            	this.$ajax('user_coupon', {
            		user_token: this.$getSync('userToken'),
            		page: this.page,
            		limit: 10,
                    status: 1,//0未领取 1未使用 2已使用 3已过期
                    money: this.money,//订单金额 满足使用条件
            	}).then(ret => {
            		if (ret.success == 1000) {
            			if (ret.detail && ret.detail.coupon && ret.detail.coupon.length > 0) {
            				this.list = this.list.concat(ret.detail.coupon);
            				this.page++;
            				this.status = 'loadmore'
            			} else {
            				this.status = 'nomore'
            			}
            		} else {
            			this.$toast(ret.msg);
            		}
            	});
            },
        }
    };
</script>

<style lang="scss">
    page{
        background-color: #f5f5f5;
    }
    .item{
        display: flex;
        justify-content: space-between;
        align-items: center;
        background-color: #fff;
        padding: 30rpx 25rpx;
        margin: 20rpx 20rpx 0;
        border-radius: 20rpx;
    }
    .img{
        width: 140rpx;
        height: 140rpx;
        margin-right: 18rpx;
    }
    .price{
        font-size: 26rpx;
        color: #f62a2a;
    }
    .price>text{
        font-size: 56rpx;
        font-weight: bold;
        padding-right: 5rpx;
    }
    .pA{
        color: #5e5d5d;
    }
    .time{
        font-size: 24rpx;
        color: #4c4c4c;
        padding-bottom: 15rpx;
    }
    .down{
        padding-top: 20rpx;
        border-top: 2rpx dashed #cccccc;
        display: flex;
        justify-content: space-between;
        align-items: center;
        font-size: 24rpx;
        color: #999999;
    }
    .btn{
        font-size: 24rpx;
        color: #8c6238;
        padding: 8rpx 10rpx;
        background-color: #f8e4cb;
        border-radius: 8rpx;
        margin-left: 20rpx;
    }

</style>
